import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: 子菜单只在路由子菜单时出现。长度>= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   如果设置为true，项目将不会显示在侧边栏中(默认为false) 如401，login等页面
 * alwaysShow: true               如果设置为true，将始终显示根菜单
 *                                如果没有设置alwaysShow，当item有多个子路由时，它将变成嵌套模式，否则不显示根菜单
 *
 * redirect: noRedirect           重定向地址，在面包屑中点击会重定向去的地址
 * name:'router-name'             设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * meta : {
    roles: ['admin','editor']    控制页面角色(可以设置多个角色)
    title: 'title'               设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'/'el-icon-x' 图标显示在侧边栏中
    breadcrumb: false            如果设置为false，则条目将隐藏在面包屑中(默认为true)
    activeMenu: '/example/list'  如果设置了路径，侧边栏将突出显示您设置的路径
  }
 */

// 静态路由，所有角色都可以访问
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    name: 'Page404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    name: 'main',
    redirect: '/main', // path为/则重定向到/main
    children: [
      {
        path: 'main',
        name: 'Main',
        component: () => import('@/views/main/index'),
        meta: { title: '首页', icon: 'el-icon-s-home' }
      }
    ]
  },

  // 意向学员
  /* {
    path: '/intentionStudent',
    component: Layout,
    name: 'intentionStudent',
    children: [
      {
        "path": "intentionStudent",
        "name": "IntentionStudent",
        "component": () => import("@/views/dschoolmange/intentionStudent/index"),
        "meta": {
          "title": "意向学员",
          "icon": ""
        }
      },
    ],
  }, */

  // 场地管理
  /* {
    path: '/siteMent',
    component: Layout,
    name: 'siteMent',
    children: [
      {
        "path": "siteMent",
        "name": "SiteMent",
        "component": () => import("@/views/dschoolmange/siteMent/index"),
        "meta": {
          "title": "场地管理",
          "icon": ""
        }
      },
    ],
  }, */

  /* {
    path: '/beAffiliatedManage',
    component: Layout,
    name: 'beAffiliatedManage',
    "meta": {
      "title": "挂靠点管理",
    },
    children: [
      {
        "path": "directSales",
        "name": "DirectSales",
        "component": () => import("@/views/dschoolmange/prenter/allStudent"),
        "meta": {
          "title": "挂靠点",
          "icon": ""
        }
      },
      {
        "path": "index",
        "name": "Index",
        "component": () => import("@/views/dschoolmange/APManagement/index"),
        "meta": {
          "title": "直营点",
          "icon": ""
        }
      },
      {
        "path": "beAffiliatedTo",
        "name": "BeAffiliatedTo",
        "component": () => import("@/views/dschoolmange/APManagement/beAffiliatedTo"),
        "meta": {
          "title": "挂靠点类别",
          "icon": ""
        }
      },

    ],

  },
  {
    path: '/prenter',
    component: Layout,
    name: 'Prenter',
    "meta": {
      "title": "预录入",
    },
    children: [
      {
        "path": "allStudent",
        "name": "AllStudent",
        "component": () => import("@/views/dschoolmange/prenter/allStudent"),
        "meta": {
          "title": "全部学员",
          "icon": ""
        }
      },
      {
        "path": "studentSign",
        "name": "StudentSign",
        "component": () => import("@/views/dschoolmange/prenter/studentSign"),
        "meta": {
          "title": "学员预约",
          "icon": ""
        }
      },
      {
        "path": "examine",
        "name": "Examine",
        "component": () => import("@/views/dschoolmange/prenter/examine"),
        "meta": {
          "title": "驾校绑定审核",
          "icon": ""
        }
      },
      {
        "path": "winprenter",
        "name": "Winprenter",
        "component": () => import("@/views/dschoolmange/prenter/winprenter"),
        "meta": {
          "title": "PC端预录入",
          "icon": ""
        }
      },
    ],
  } */

]

const createRouter = () => new Router({
  isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由 这里是我自定义的
  scrollBehavior: () => ({ y: 0 }), // 页面跳转让滚动条回到顶部
  routes: constantRoutes
})

const router = createRouter()

// 退出等操作 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
